﻿@{
    Bundle("jquery_validate");
}
           
<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('@ID("#form")').validate({
            rules: {
                customerName: {
                    required: true
                },
                sellerName: {
                    required: true
                }
            }
        });
        jQuery('@ID("#hidden_customer")').bind('change', function () {
            jQuery.ajax({
                type: 'post',
                url: '@Url.Action(Loc.Act("Addresses").Ctrl("Customer"))',
                dataType: 'json',
                data: {
                    customerID: jQuery('@ID("#hidden_customer")').val()
                },
                success: function (rsp) {
                    jQuery('@ID("#ddl_billing_address")').empty();
                    jQuery.each(rsp, function (k, v) {
                        jQuery('@ID("#ddl_billing_address")').append('<option value=' + v.id + '>' + v.value + '</option>');
                    });
                }
            });
        });
        jQuery('@ID("#hidden_customer")').bind('change', function () {
            jQuery.ajax({
                type: 'post',
                url: '@Url.Action(Loc.Act("Addresses").Ctrl("Customer"))',
                dataType: 'json',
                data: {
                    customerID: jQuery('@ID("#hidden_customer")').val()
                },
                success: function (rsp) {
                    jQuery('@ID("#ddl_shipping_address")').empty();
                    jQuery.each(rsp, function (k, v) {
                        jQuery('@ID("#ddl_shipping_address")').append('<option value=' + v.id + '>' + v.value + '</option>');
                    });
                }
            });
        });
        jQuery('@ID("#hidden_seller")').bind('change', function () {
            jQuery.ajax({
                type: 'post',
                url: '@Url.Action(Loc.Act("Addresses").Ctrl("Seller"))',
                dataType: 'json',
                data: {
                    sellerID: jQuery('@ID("#hidden_seller")').val()
                },
                success: function (rsp) {
                    jQuery('@ID("#ddl_seller_address")').empty();
                    jQuery.each(rsp, function (k, v) {
                        jQuery('@ID("#ddl_seller_address")').append('<option value=' + v.id + '>' + v.value + '</option>');
                    });
                }
            });
        });
        jQuery('@ID("#txt_customer")').autocomplete({
            source: function (request, response) {
                jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("Customer")))', request, response);
            },
            minLength: 3,
            select: function (event, ui) {
                jQuery('@ID("#hidden_customer")').val(ui.item.id);
                jQuery('@ID("#hidden_customer")').change();
            }
        });
        jQuery('@ID("#txt_seller")').autocomplete({
            source: function (request, response) {
                jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("Seller")))', request, response);
            },
            minLength: 3,
            select: function (event, ui) {
                jQuery('@ID("#hidden_seller")').val(ui.item.id);
                jQuery('@ID("#hidden_seller")').change();
            }
        });
        jQuery.ajax({
            type: 'post',
            url: '@Url.Action(Loc.Act("SalesModels").Ctrl("Order"))',
            dataType: 'json',
            success: function (rsp) {
                var ddl = jQuery('@ID("#ddl_sales_model")');
                ddl.empty();
                jQuery.each(rsp, function (k, v) {
                    ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                });
            }
        });
        jQuery.ajax({
            type: 'post',
            url: '@Url.Action(Loc.Act("ShippingMethods").Ctrl("Order"))',
            dataType: 'json',
            success: function (rsp) {
                var ddl = jQuery('@ID("#ddl_shipping_method")');
                ddl.empty();
                jQuery.each(rsp, function (k, v) {
                    ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                });
            }
        });
    });
</script>
<form id="@ID("form")" action="@Url.Action(Loc.Act("Create").Ctrl("Order"))" method="post">
    <input type="hidden" name="flags" value="None" />
    <table>
        <tr>
            <td>
                <label>@T(Res.Name("SalesModel"))</label>
            </td>
            <td>
                <select id="@ID("ddl_sales_model")" name="salesModelID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("ShippingMethod"))</label>
            </td>
            <td>
                <select id="@ID("ddl_shipping_method")" name="shippingMethodID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Customer"))</label>
            </td>
            <td>
                <input id="@ID("hidden_customer")" type="hidden" name="customerID" />
                <input id="@ID("txt_customer")" type="text" name="customerName" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("BillingAddress"))</label>
            </td>
            <td>
                <select id="@ID("ddl_billing_address")" name="billingAddressID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("ShippingAddress"))</label>
            </td>
            <td>
                <select id="@ID("ddl_shipping_address")" name="shippingAddressID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Seller"))</label>
            </td>
            <td>
                <input id="@ID("hidden_seller")" type="hidden" name="sellerID" />
                <input id="@ID("txt_seller")" type="text" name="sellerName" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("SellerAddress"))</label>
            </td>
            <td>
                <select id="@ID("ddl_seller_address")" name="sellerAddressID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("HandlingFee"), JDM.String(Svc.Localization.Currency.Code))</label>
            </td>
            <td>
                <input type="text" name="handlingFee" value="@Svc.Price(Decimal.Zero)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("TaxAmount"), JDM.String(Svc.Localization.Currency.Code))</label>
            </td>
            <td>
                <input type="text" name="taxAmount" value="@Svc.Price(Decimal.Zero)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("DiscountAmount"), JDM.String(Svc.Localization.Currency.Code))</label>
            </td>
            <td>
                <input type="text" name="discountAmount" value="@Svc.Price(Decimal.Zero)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("ShippingPrice"), JDM.String(Svc.Localization.Currency.Code))</label>
            </td>
            <td>
                <input type="text" name="shippingPrice" value="@Svc.Price(Decimal.Zero)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Subtotal"), JDM.String(Svc.Localization.Currency.Code))</label>
            </td>
            <td>
                <input type="text" name="subtotal" value="@Svc.Price(Decimal.Zero)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Total"), JDM.String(Svc.Localization.Currency.Code))</label>
            </td>
            <td>
                <input type="text" name="total" value="@Svc.Price(Decimal.Zero)" />
            </td>
        </tr>
    </table>
    <ul class="bar toolbar">
        <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
    </ul>
</form>
